﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel;
namespace EnterpriseManagement.Models
{
    #region  Model
    public class SearchEmployeeModel
    {

        [DisplayName("员工ID")]
        public string EmployeeId { get; set; }

        [DisplayName("员工姓名")]
        public string Name { get; set; }

        [DisplayName("职位")]
        public string Position { get; set; }

        [DisplayName("性别")]
        public string Sex { get; set; }

        [DisplayName("在职状态")]
        public string EmployeeStatus { get; set; }

    }
    #endregion

    #region DbHelper

    public partial class DbHelper
    {
        /// <summary>
        /// 条件查询项目组
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List<Employee> SearchEmployee(SearchEmployeeModel model)
        {
            using (ProjectEntities currentContext = new ProjectEntities())
            {
                var query = from e in currentContext.Employees 
                            select e;

                if (!string.IsNullOrEmpty(model.EmployeeId))
                    query = query.Where(e => e.employee_id == model.EmployeeId);

                if (!string.IsNullOrEmpty(model.Name))
                    query = query.Where(e => e.name == model.Name);

                if (!string.IsNullOrEmpty(model.Sex))
                    query = query.Where(e => e.sex == model.Sex);

                if (!string.IsNullOrEmpty(model.EmployeeStatus))
                    query = query.Where(e=>e.employee_status == model.EmployeeStatus);

                if (!string.IsNullOrEmpty(model.Position))
                    query = query.Where(e => e.position == model.Position);

           
                return query.ToList();
            }
        }
    }

    #endregion

    #region FormsService
    public partial class FormsService
    {
        /// <summary>
        /// 条件查询员工信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List<Employee> SearchEmployee(SearchEmployeeModel model)
        {
            return DbHelper.SearchEmployee(model);
        }
    }

    #endregion
}